'''
Created on Apr 5, 2016

@author: JimmyMo
'''
from boot.boot import Boot
from database import dao

class RabbitMQBoot(Boot):
    def _parse_options(self, raw_options):
        self.host = 'localhost'
        self.queue_name = 'logpumper_q'
    def __init__(self, raw_options, start_method):
        super().__init__(raw_options, start_method)
    def boot(self):
        try:
            connection = dao.get_rabbitmq_connection(self.host)
            channel = connection.channel()
            channel.queue_declare(queue=self.queue_name)
            channel.basic_consume(consumer_callback=self.callback, queue=self.queue_name, no_ack=False)
            print(' [*] Waiting for messages. To exit press CTRL+C')
            channel.start_consuming()
        except Exception as ex:
            print(ex)
        pass
    def callback(self, ch, method, properties, body):
        print('callback received...')
        print("processing...")
        self.start_method()
        print("process done, sending ack...")
        ch.basic_ack(delivery_tag=method.delivery_tag)
        pass